int solution(vector<int> &A) {
    // write your code in C++14 (g++ 6.2.0)
    int total_count = 0;
    while(A.size()){
        int curr_count = 0;
        int left = 0, right = 0;
        for(int i=0; i<A.size();){
            if(A[i]){
                if(left == 0) {
                    curr_count++;
                    left = 1;
                }
                A[i]--;
            }
            else{
                left = 0;
            }
            if(A[i] == 0 && (i==0 || i=A.size()-1)) A.erase(A.begin()+i);
            else i++;
        }
        total_count += curr_count;
    }
    return total_count;
}

int solution(vector<int> &A) {
    // write your code in C++14 (g++ 6.2.0)
    int total_count = 0;
    int left_idx=0, right_idx=A.size()-1;
    while(left_idx <= right_idx){
        int curr_count = 0;
        int left = 0, right = 0;
        for(int i=left_idx; i<=right_idx; i++){
            if(A[i]){
                if(left == 0) {
                    curr_count++;
                    left = 1;
                }
                A[i]--;
            }
            else{
                left = 0;
            }
            if(A[i] == 0){
                if(i==left_idx) left_idx++;
                else if(i==right_idx) right_idx--;
            }
        }
        total_count += curr_count;
    }
    return total_count;
}

int main(int argc, char* argv[]){

    
    return 0;
}

int solution(vector<int> &A, vector<int> &B) {
    // write your code in C++14 (g++ 6.2.0)
    int N = A.size()+1;
    unordered_set<int> a_container;
    for(auto it:A) a_container.insert(it);
    if (a_container.size() != (N-1)) return 0;
    for(int i=0; i<B.size(); i++){
        auto it = a_container.find(B[i]);
        if(it != a_container.end()) continue;
        else return B[i];
    }
    return 0;
}